<%--
  Created by IntelliJ IDEA.
  User: zmjha
  Date: 2020/6/19
  Time: 21:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<html>
<head>
    <title>修改信息页面</title>
</head>
<body>
<div id="messsage"></div>
<input id="id" type="text" value="${book.id}" style="display: none" >
<div>书名:<input id="bookName" type="text" value="${book.bookName}"><div id="messsage1"></div></div><br>
<div>作者:<input id="author" type="text" value="${book.author}"><div id="messsage2"></div></div><br>
<div>价格:<input id="price" type="text" value="${book.price}"><div id="messsage3"></div></div><br>
<button type="button" onclick="sumbit()">提交</button>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">

    function sumbit() {
        var id=$("#id").val();
        var bookName=$("#bookName").val();
        var author=$("#author").val();
        var price=$("#price").val();
        if(id==undefined|id.trim()==""){
           var id=0;
        }
        if(bookName==undefined||bookName.trim()==""){
            $("#messsage1").text("对不起,书名不能为空");
            return;
        }


        if(author==undefined||author.trim()==""){
            $("#messsage2").text("对不起,作者不能为空");
            return;
        }


        if(price==undefined||price.trim()==""){
            $("#messsage3").text("对不起,价格不能为空");
            return;
        }
        $.ajax({
            url:"addOrUpdate",
            type:"post",
            dataType:"json",
            data:{"id":id,"bookName":bookName,"author":author,"price":price},
            success:function (data) {
                if (data.code==1){
                    alert(data.mes)
                    location.href="tomain";
                }else {
                    $("#messsage").text(data.mes)
                }
            }
        })

    }
</script>
</html>
